#ifndef _CRULERBOX_H_
#define _CRULERBOX_H_

#include <buola/widgets/cwidget.h>

#include <buola/utility/uevent.h>

namespace buola { namespace gui {

class CRulerBox : public CWidget
{
public:
    class SField
    {
    public:
        TID mID;
        std::wstring mName;
        PIcon mIcon;
        double mMinSize;
        double mSize;
        double mPos;
        bool mHighlight;
        img::CColor mHighlightColor;
    };

public:
    CRulerBox();
    ~CRulerBox();

    void RemoveFields();
    void AddField(TID pID,const std::wstring &pTitle,PIcon pIcon,double pSize);

    const SField &GetField(int i)    {   return *mFields[i];  }

    TID GetIDAt(double pPos);

    void SetScroll(double);
    void SetFieldName(int i,const std::wstring &pName);

    void HighlightNone();
    void HighlightField(TID pID,const img::CColor &pColor);

protected:
    void DrawField(img::CGC*,const SField&,bool pUnder);
    void DrawAll(img::CGC*);

    int GetEdgeAt(const CPoint_d&);
    int GetItemAt(const CPoint_d&);

    void UpdatePointer();

public:
////////////// Event handling //////////////
    virtual void OnExpose(const CExposeEvent &pE);
    virtual void OnButtonDown(const CMouseEvent &pE);
    virtual void OnButtonUp(const CMouseEvent &pE);
    virtual void OnMouseMove(const CMouseEvent &pE);
    virtual void OnMouseOut(const CMouseEvent &pE);
    virtual void OnMouseIn(const CMouseEvent &pE);

    UEvent<void(TID,double)> eMoved;
    UEvent<void(double)> eFirstMoved;

protected:
    bool mSorting;
    bool mDragging;
    double mDragPos;
    double mDragRootPos;
    bool mInside;

    CPoint_d mTextPos;
    CSize_d mTextSize;

    img::PFont mFont;

    int mSelected;
    int mUnder;

    CPoint_d mScrollPos;
    
    std::vector<std::unique_ptr<SField>> mFields;
};

/*namespace gui*/ } /*namespace buola*/ }

#endif
